﻿ var map;
 
    //变量
    //点 points
    //线 lines
    //面 surfaces
    var pointicon = new google.maps.MarkerImage('../themes/images/picon.png',
      new google.maps.Size(20, 20),
      new google.maps.Point(0,0),
      new google.maps.Point(10, 10));
    var lineicon = new google.maps.MarkerImage('../themes/images/licon.png',
      new google.maps.Size(7, 7),
      new google.maps.Point(0,0),
      new google.maps.Point(3, 3));
    var points = [];
    var lines = [];
    var surfaces = [];
    var pointlist=[];
            var latmax=-90.0;
            var lontmax=-180.0;
            var latmin=90.0;
            var lontmin=180.0;
    //end of 变量
 
 $(document).ready(function(){
    //start 地图初始化
        var latlng = new google.maps.LatLng(31.918123, 118.679823);
        var myOptions = {
          zoom: 10,
          center: latlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    //end of 地图初始化
    });
    
    //弹出框信息(函数)
    function contentString(name,B,L,H,time,attributes,status,imgpath,remarkstr)
    {
        var str = '<div class=\"point\">'+
                  '<span class="featuretype"><strong>点要素</strong><span>'+name+'</span></span>'+
                  '<span><strong>采集时间：</strong><span>'+time+'</span></span>'+
                  '<span><strong>作业方式：</strong><span>'+status+'</span></span>'+
                  '<span><strong>经度：</strong><span>'+B+'</span></span>'+
                  '<span><strong>纬度：</strong><span>'+L+'</span></span>'+
                  '<span><strong>高：</strong><span>'+H+'</span></span>'+
                  '<span><strong>属性：</strong><span>'+attributes+'</span></span>';
        if(imgpath!="&nbsp;") str += '<img src=\"'+imgpath+'\" width="300" height="200" /></div>';
        else str += '</div>';
        return remarkstr+str;
    }
    //end of 弹出框
    
    //添加地标(函数)
    function addMarker(pointobj,pointicon,arrays,remarkstr) {
          var Latlng = new google.maps.LatLng(pointobj.B, pointobj.L);
          var strcontent = contentString(pointobj.name,pointobj.B,pointobj.L,pointobj.H,pointobj.time,pointobj.attribute,pointobj.status,pointobj.imgpath,remarkstr);
          var infowindow = new google.maps.InfoWindow({
                content: strcontent,
                position:Latlng
            });
          marker = new google.maps.Marker({
            position: Latlng,
            map: map,
            icon: pointicon
          });
          google.maps.event.addListener(marker, 'click', function() {
               infowindow.open(map);
            });
          marker.setMap(map);  
          arrays.push(marker);
          pointlist.push(marker);
          GetExtent(pointobj)
    }
    //end of 添加地标
    
    //添加线(函数)
    function addLine(lineobj,lineicon,arrays){
           var remark = '<div class=\"point point1\">'+
                        '<span class="featuretype1"><strong>线要素</strong><span>'+lineobj.name+'</span></span>'+
                        '<span><strong>采集时间：</strong><span>'+lineobj.time+'</span></span>'+
                        '<span><strong>作业方式：</strong><span>'+lineobj.status+'</span></span>'+
                        '<span><strong>节点个数：</strong><span>'+lineobj.pointlist.length+'</span></span>'+
                        '<span><strong>属性：</strong><span>'+lineobj.attributes+'</span></span>';
           if(lineobj.imgpath!="&nbsp;") remark += '<img src=\"'+lineobj.imgpath+'\" width="300" height="200" /></div>';
           else remark += '</div>';
           var pointlist = [];
           var flightPlanCoordinates = [];
           for(var i=0;i<lineobj.pointlist.length;i++){
                addMarker(lineobj.pointlist[i],lineicon,pointlist,remark);
                flightPlanCoordinates.push(pointlist[i].getPosition());
           }
                    
           var flightPath = new google.maps.Polyline({
                path: flightPlanCoordinates,
                strokeColor: "#666",
                strokeOpacity: 1.0,
                strokeWeight: 3
           });

           flightPath.setMap(map);
           arrays.push(flightPath);
    }
    //end of 添加线
    
    //添加面(函数)
    function addSurface(surfaceobj,surfaceicon,arrays){
           var remark = '<div class=\"point point1\">'+
                        '<span class="featuretype1"><strong>面要素</strong><span>'+surfaceobj.name+'</span></span>'+
                        '<span><strong>采集时间：</strong><span>'+surfaceobj.time+'</span></span>'+
                        '<span><strong>作业方式：</strong><span>'+surfaceobj.status+'</span></span>'+
                        '<span><strong>节点个数：</strong><span>'+surfaceobj.pointlist.length+'</span></span>'+
                        '<span><strong>属性：</strong><span>'+surfaceobj.attributes+'</span></span>';
           if(surfaceobj.imgpath!="&nbsp;") remark += '<img src=\"'+surfaceobj.imgpath+'\" width="300" height="200" /></div>';
           else remark += '</div>';
           var pointlist = [];
           var flightPlanCoordinates = [];
           for(var i=0;i<surfaceobj.pointlist.length;i++){
                addMarker(surfaceobj.pointlist[i],lineicon,pointlist,remark);
                flightPlanCoordinates.push(pointlist[i].getPosition());
           }
           
           flightPath = new google.maps.Polygon({
                paths: flightPlanCoordinates,
                strokeColor: "#666",
                strokeOpacity: 1.0,
                strokeWeight: 3,
                fillColor: "#666",
                fillOpacity: 0.2
              });  

           flightPath.setMap(map);
           arrays.push(flightPath);
    }
    //end of 添加面
    
 
    
   

function SearchRTDInfo() {
            latmax=-90.0;
            lontmax=-180.0;
            latmin=90.0;
            lontmin=180.0;
            ClearRTDInfo();
    var strlist = document.getElementById("ListBoxUsers"); //获取Listbox
    var pattern = /^\d{4}\-\d{1,2}\-\d{1,2}$/;
    var startTime = document.getElementById("txtStartTime").value;
    var endTime = document.getElementById("txtEndTime").value;
    var flag1 = pattern.test(startTime);
	if(!flag1)
	{
	    alert("起始日期格式不正确！");
	    return;
	}
	var flag2=pattern.test(endTime);
	if(!flag2)
	{
	     alert("结束日期格式不正确！");
	     return;
	}
    var str = "";
    if (strlist.options.length > 0 && startTime != '' && endTime != '') {
        for (var i = 0; i < strlist.options.length; i++) {
            if (strlist.options[i].selected == true) {
                var j = strlist.options[i].value;
                str += j + ";"; //把Value值串起来
            }
        }
        if (str != '' && str != '0000') {
            var strValue = str.replace(/;$/, "");   //去掉最后一个逗号
             var xmlURL = "CreateQ5Json.aspx?id=" + strValue + "&Start=" + startTime + "&End=" + endTime;
              //start 请求数据
        $.ajax({
            type:"GET",
            url:xmlURL,
            dataType:"json",
            success:function(msg){
                if(msg==null)
                {
                    alert("没有符合条件的记录！");
                    return;
                }

                if(msg.point!=null)
                {//点
                    for(var i=0;i<msg.point.length;i++)
                    {
                        addMarker(msg.point[i],pointicon,points,"");
                        
                    }
                }
                if(msg.line!=null)
                {//线
                    for(var j=0;j<msg.line.length;j++)
                    {
                        addLine(msg.line[j],lineicon,lines);
                    }
                }
                if(msg.surface!=null)
                {//面
                    for(var k=0;k<msg.surface.length;k++)
                    {
                        addSurface(msg.surface[k],lineicon,surfaces);
                    }
                }
                latmax=parseFloat(latmax);
                latmin=parseFloat(latmin);
                lontmax=parseFloat(lontmax);
                lontmin=parseFloat(lontmin);
                var centb=(latmax+latmin)/2.0;
                var centl=(lontmax+lontmin)/2.0;
               var latlng = new google.maps.LatLng(centb, centl);  
               map.panTo(latlng);
               map.setZoom(10);
            },
            error:function(msg){
                var temp=msg;
                alert("加载数据出错！");
            }
        });
    //end of 请求数据
        }
        else
        {
            alert("请选择至少一个RTD用户！");
            return;
        }
    } 
}
function GetExtent(pointobj)
{
    if(pointobj.B>latmax)
    {
        latmax=pointobj.B;
    }
    if(pointobj.B<latmin)
    {
        latmin=pointobj.B;
    }
    if(pointobj.L>lontmax)
    {
        lontmax=pointobj.L;
    }
    if(pointobj.L<lontmin)
    {
        lontmin=pointobj.L;
    }
}
function ClearRTDInfo()
{
        var latlng = new google.maps.LatLng(31.918123, 118.679823);
        map.panTo(latlng);
        map.setZoom(10);
 if (points) {
      for (i in points) {
      points[i].setMap(null);
      }
      points.length = 0;
    }
     if (lines) {
     for (i in lines) {
     lines[i].setMap(null);

      }
      lines.length = 0;
    }
     if (surfaces) {
    for (i in surfaces) {
    surfaces[i].setMap(null);
        
      }
      surfaces.length = 0;
    }
    if(pointlist) {
    for (i in pointlist) {
    pointlist[i].setMap(null);
        
      }
      pointlist.length = 0;
    }
}